public int CreateUser(string email, string pass, string user) { SurveyPortalDBDataContext sql = new SurveyPortalDBDataContext(); try { var check = (from u in sql.users where u.username == user select u).FirstOrDefault(); if (check.username.ToLower() == user.ToLower()) { return(2); } } catch (Exception e) { } try { var check = (from u in sql.users where u.email == email select u).FirstOrDefault(); if (check.email.ToLower() == email.ToLower()) { return(3); } } catch (Exception e) { } user adduser = new user { email = email, password = pass, username = user, isEnabled = false }; sql.users.InsertOnSubmit(adduser); try { sql.SubmitChanges(); RNG rng = new RNG(); string activation = ""; for (int i = 0; i < 16; i++) { int type = rng.NextRandom(0, 1); char c; if (type == 0) { c = (char)rng.NextRandom(48, 57); } else { c = (char)rng.NextRandom(65, 90); } activation += c; } validationcode valid = new validationcode { userid = adduser.id, code = activation }; sql.validationcodes.InsertOnSubmit(valid); try { sql.SubmitChanges(); } catch (Exception n) { } SMTPHandler smtp = new SMTPHandler(); smtp.SendActivation(activation, email, user, pass); return(0); } catch (Exception e) { return(1); } }
partial void Deletevalidationcode(validationcode instance);
public int CreateUser(string email, string pass, string user) { SurveyPortalDBDataContext sql = new SurveyPortalDBDataContext(); try { var check = (from u in sql.users where u.username == user select u).FirstOrDefault(); if (check.username.ToLower() == user.ToLower()) { return 2; } } catch (Exception e) { } try { var check = (from u in sql.users where u.email == email select u).FirstOrDefault(); if (check.email.ToLower() == email.ToLower()) { return 3; } } catch (Exception e) { } user adduser = new user { email = email, password = pass, username = user, isEnabled = false }; sql.users.InsertOnSubmit(adduser); try { sql.SubmitChanges(); RNG rng = new RNG(); string activation = ""; for(int i = 0; i < 16; i++) { int type = rng.NextRandom(0, 1); char c; if(type == 0) { c = (char)rng.NextRandom(48, 57); } else { c = (char)rng.NextRandom(65, 90); } activation += c; } validationcode valid = new validationcode { userid = adduser.id, code = activation }; sql.validationcodes.InsertOnSubmit(valid); try { sql.SubmitChanges(); } catch(Exception n) { } SMTPHandler smtp = new SMTPHandler(); smtp.SendActivation(activation, email, user, pass); return 0; } catch (Exception e) { return 1; } }
partial void Insertvalidationcode(validationcode instance);
partial void Updatevalidationcode(validationcode instance);
private void detach_validationcodes(validationcode entity) { this.SendPropertyChanging(); entity.user = null; }