Home » Web Development » Page 3

I've been following a tutorial for a login/register authentication
application. I keep getting the error "Can't set headers after they
are sent" whenever I send POST requests. I tried to console.log the
request body and it were empty. I don't know where I did wrong. Please
help.



users.js



var express = require('express');
var router = express.Router();
var User = require('../models/User')

/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});

router.get('/register', function(req, res, next) {
res.render('register', {title:'Register'});
});

router.get('/login', function(req, res, next) {
res.render('login', {title: 'Login'})
});

router.post('/register', function(req, res, next) {
var name = req.body.name;
var email = req.body.email;
var username = req.body.username;
var password = req.body.password;
var password2 = req.body.password2;

if (req.files && req.files.profileimage) {
console.log('Uploading file...');

var profileimageOriginalName =
req.files.profileimage.originalname;
var profileimageName = req.files.profileimage.name;
var profileimageMime = req.files.profileimage.mimetype;
var profileimageExt = req.files.profileimage.extension;
var profileimageSize = req.files.profileimage.size;
var profileimagePath = req.files.profileimage.path;
} else {
var profileimageName = 'noimage.png'
}

req.checkBody('name', 'Name field is required').notEmpty();
req.checkBody('email', 'Email field is required').notEmpty();
req.checkBody('email', 'Email field is not valid').isEmail();
req.checkBody('username', 'Username field is required').notEmpty();
req.checkBody('password', 'Password field is required').notEmpty();
req.checkBody('password2', 'Password does not
match').equals(req.body.password);
var errors = req.validationErrors()

if (errors) {
res.render('register', {
errors: errors,
name: name,
email: email,
username: username,
password: password,
password2: password2
});
} else {
var newUser = new User({
name: name,
email: email,
username: username,
password: password,
profileimage: profileimageName
})
}

User.createUser(newUser, function(err, user) {
if (err) throw err;
console.log(user);
})

req.flash('sucess', 'You are now registered and may login');
res.location('/');
res.redirect('/');
})
module.exports = router;


app.js



var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var passport = require('passport');
var LocalStrategry = require('passport-local').strategy;
var bodyParser = require('body-parser');
var expressValidator = require('express-validator');
var flash = require('connect-flash');
var multer = require('multer')
var mongo = require('mongodb');
var mongoose = require('mongoose');
var db = mongoose.connection

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// handle file upload
var upload = multer({dest: './uploads'});

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));


app.use(session({
secret: 'secret',
saveUninitialized: true,
resave: true
}))

app.use(passport.initialize());
app.use(passport.session());

app.use(expressValidator({
errorFormatter: function(param, msg, value) {
var namespace = param.split('.')
, root = namespace.shift()
, formParam = root;

while(namespace.length) {
formParam += '[' + namespace.shift() + ']';
}
return {
param : formParam,
msg : msg,
value : value
};
}
}));


app.use(flash())
app.use(function (req, res, next) {
res.locals.messages = require('express-messages')(req, res);
next();
});

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});


module.exports = app;

this code shows to me every student that do not read the notes so I
need the counter of these unread to print it
how can get the sum of all unread notes ?



 $query=mysql_query("SELECT * FROM students WHERE
parents_id='".$pid."'");
while($r=mysql_fetch_assoc($query)){
echo'<tr>';
echo'<td><b>'.$r['first_name'].' '.
$r['last_name'].'</b></td>';
echo'<td>'.$r['class_name'].'</td>';
$quer=mysql_query("SELECT count(id) FROM notes WHERE
student_id='".$r['id']."' AND isread='0' ");
$count=mysql_fetch_array($quer);
$c=$count[0];
echo'<td><b><span
style="color:red;text-align:center;">('.$c.')
'.'UnRread</b></td>';
echo'<td><b>'."<a
href=viewnote.php?viewnote&sid=".$r['id']."&name=".$r['first_name']."&last=".$r['last_name']."'
>View</a>".'</b></td>';
echo'</tr>';

I have string array with columns I want to select:



String[] columns = {"col1", "col2", "col3"};


The columns might change in the future, but will always be a subset
of available columns.



I cannot find a SQLiteDatabase API that lets me pass
this array as columns. The only solution I have so far is to just
string join the columns with , as separator and add it
into my query string and perform a rawQuery.



Is there a better solution?



EDIT



The query is a JOIN query.

I am trying to post a variable within a if clause, but the php
document is not receiving the variable.
Here is some Code:



JS:



if(data.details.payment_type =="sofo")    {
var orderid = data.details.order_id;
$.post("LinkToPhpDocument.php", { orderidvalue: orderid });
window.location.replace("LinkToPhpDocument.php");
}


PHP



$orderID = $_POST['orderidvalue'];

I have faced with an issue with data binding for different layouts.
I have layout file for different orientation.
For portrait mode:



<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>
</layout>


and for landspace mode:



<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent" />

<FrameLayout
android:id="@+id/extra_container"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent" />

</LinearLayout>
</layout>


And when I use it for binding via



ViewBinding binding = DataBindingUtil.setContentView(this,
R.layout.view);


I have no access for extraContainer from current
binding.



Possible solution to add the view with same id and check the view
class in runtime. Any other solutions ?

I am dealing with the thumbnail in Android. Even though I use the
function ThumbnailUtils.createVideoThumbnail provided by
Android, it gets black bitmap.



I start my research and find out some links:

1/ href="http://stackoverflow.com/questions/27351228/thumbnailutils-createvideothumbnail-return-null-bitmap-for-mp4-file">Thumbnail
null

2/ href="http://stackoverflow.com/questions/13303269/video-thumbnail-return-null">Video
Thumbnail return null



However, I checked my returned bitmap and figure out that it is not
null.



Please let me know if you have any ideas.



Any suggestion would be appreciated. Thank you in advance!

Can we have multiple processors and single writer to write data in
two different tables in spring batch

I have a list of T-objects. Each of this objects has a
list of S-objects. I want to show the
List<S>-data. That for I am using nested
RecyclerView.



Since I want to change the data of the S-objects at
runtime I use EditText to show and edit the data.



When a button is pressed I want to save all changed
S-objects in the list of the seleceted T
obeject.



How and in which class can I iterate this
List<S>?
Are DataObservers the way to go? But I can not find any
good examples of this observers.

I've a JSON like below in my angular controller, which i need to
post to Spring controller.



var items={"A":"aa",
"B":"bb",
"C":{"D":"dd", "E":"ee"}
};

$http.post('localhost:8082/ProjectName/posting',items)
.success(function(data,status,headers, config){
alert("success");
})
.error(function(error){
alert(error);
});


In my Spring controller



@RestController
public class ForPost{
@RequestMapping(value="/posting",method=RequestMethod.POST)
public @ResponseBody List forPosting(@RequestBody PostingModel
postingModel){
System.out.println("Print all values received");
.
.
.
.
}
}


I'm thinking for this kind of nested JSON, I need to have
nested POJO.
something like:



public class PostingModel{
String A;
String B;
POJOForC C;
/* getter setter below*/
}

puublic class POJOForC{
String D;
String E;
/* getter setter below*/
}


I get error message: The request sent by client was
syntactically incorrect().

Am I accepting the values correctly? Need to fix something in
POJO?

I am trying to package everything in C:AppWeb* into an
installer.



If the database sub-folder mysqldata exists, then I
do not want to replace these files.



This is my Inno Setup script:



[Files]
Source: "C:AppWebxampp-control.exe"; DestDir: "{app}"; Flags:
ignoreversion
Source: "C:AppWeb*"; DestDir: "{app}"; Flags: ignoreversion
recursesubdirs createallsubdirs
Source: "C:AppWeb*"; DestDir: "{app}"; Excludes: "C:AppWebmysqldata*";
Flags: ignoreversion recursesubdirs createallsubdirs; Check:
DirExists(ExpandConstant('{app}mysqldata*'))


The files in mysqldata still get replaced.



I want the installer to avoid overwriting the data folder if the
application is already installed (i.e. performing an upgrade).


- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow