예제 #1
0
        public SignupResultModel SignupStandardUser(UserModel user)
        {
            SignupResultModel model = new SignupResultModel();

            string cmd = "INSERT INTO USERS(GlobalID, UserID, LoginType, Password, FirstName, LastName, CreateDate, IsActivated)";

            cmd += "VALUES(@GlobalID, @UserID, @LoginType, @Password, @FirstName, @LastName, @CreateDate, @IsActivated)";

            SqlParameter globalid      = new SqlParameter("@GlobalID", user.GlobalID);
            SqlParameter userid        = new SqlParameter("@UserID", user.UserID);
            SqlParameter userlogintype = new SqlParameter("@LoginType", user.UserLoginType);
            SqlParameter password      = new SqlParameter("@Password", user.PasswordHash);
            SqlParameter fname         = new SqlParameter("@FirstName", user.FirstName);
            SqlParameter lname         = new SqlParameter("@LastName", user.LastName);
            SqlParameter createdate    = new SqlParameter("@CreateDate", user.CreateDate);
            SqlParameter isactive      = new SqlParameter("@IsActivated", user.IsActivated);

            try
            {
                //- check if user exists
                bool doesExist = CheckUserExists(user.UserID);

                if (doesExist)
                {
                    model.ResultStatus = SignupResultType.UserExists;
                    model.Message      = "The user id already exists";
                    return(model);
                }

                // - insert new user into database
                int queryresult = DatabaseHelper.ExecuteNonQuery(cmd, _connectionString,
                                                                 globalid, userid, userlogintype, password, fname, lname, createdate, isactive);

                if (queryresult < 0)
                {
                    model.ResultStatus = SignupResultType.UnexpectedException;
                    model.Message      = "The database was unable to add the user record";
                }
                else
                {
                    model.ResultStatus = SignupResultType.Success;
                    model.Message      = "User account successfully added";
                }
            }
            catch (Exception ex)
            {
                LogMessageModel message = new LogMessageModel(LogStatus.Error,
                                                              string.Format("An error occurred during user signup within DatabaseManager.SignupStandardUser: {0}", ex.Message), -1);

                model.ResultStatus = SignupResultType.UnexpectedException;
                model.Message      = string.Format("An exception occurred while attempted to add the user account: {0}", ex.Message);
            }

            return(model);
        }
예제 #2
0
        public string SignupStandardUser(string user)
        {
            string result = "";

            UserModel signupUser = JsonTools.Deserialize <UserModel>(user);

#warning PASSWORD MUST BE ENCRYPTED.  PREFERABLY THIS SHOULD BE DONE ON THE CLIENT

            SignupResultModel model = (SignupResultModel)DatabaseManager.Instance.SignupStandardUser(signupUser);

            //- Create json object based on the result type
            result = JsonTools.Serialize <SignupResultModel>(model);

            return(result);
        }
예제 #3
0
        private void OnSignupTouchUpInside(object sender, EventArgs args)
        {
            string data = JsonTools.Serialize <UserModel> (User);

            data = string.Format("user= {0}", data);
            WebClient client = new WebClient();

            client.Headers [HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            string result = client.UploadString(_signupurl, data);             //client.UploadString (_signupurl, "{data: 'believe me!'}");//

            SignupResultModel model = JsonTools.Deserialize <SignupResultModel> (result);

            if (OnSignupCompleted != null)
            {
                OnSignupCompleted(this, model);
            }
        }
예제 #4
0
        public IHttpActionResult /*HttpResponseMessage*/ Post(SignupBindingModel model)
        {
            bool isValid = true;
            ErrorsSignupBindingModel errors = new ErrorsSignupBindingModel();

            if (string.IsNullOrEmpty(model.UserName))
            {
                errors.username = "******";
                isValid         = false;
            }
            if (string.IsNullOrEmpty(model.Email))
            {
                errors.email = "This field is required";
                isValid      = false;
            }
            try
            {
                MailAddress emailAddress = new MailAddress(model.Email);
            }
            catch
            {
                errors.email = "Email is invalid";
                isValid      = false;
            }
            if (string.IsNullOrEmpty(model.Password))
            {
                errors.password = "******";
                isValid         = false;
            }
            if (!model.Password.Equals(model.PasswordConfirmation))
            {
                errors.passwordConfirmation = "Passwords must match";
                isValid = false;
            }
            if (string.IsNullOrEmpty(model.Timezone))
            {
                errors.timezone = "This field is required";
                isValid         = false;
            }
            SignupResultModel result = new SignupResultModel
            {
                errors  = errors,
                isValid = isValid
            };

            if (!isValid)
            {
                return(Content(HttpStatusCode.BadRequest, result));
            }
            //return Request.CreateResponse(HttpStatusCode.BadRequest, result);

            HttpClient client     = new HttpClient();
            string     jsonObject = JsonConvert.SerializeObject(new
            {
                Email           = model.Email,
                Password        = model.Password,
                ConfirmPassword = model.Password
            });

            var request = HttpContext.Current.Request;
            var url     = request.Url.GetLeftPart(UriPartial.Authority) +
                          request.ApplicationPath + "/api/Account/Register";
            var content  = new StringContent(jsonObject, Encoding.UTF8, "application/json");
            var response = client.PostAsync(url, content).Result;

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(Content(HttpStatusCode.BadRequest, result));
            }

            ICryptoService cryptoService = new PBKDF2();
            //save this salt to the database
            string salt = cryptoService.GenerateSalt();
            //save this hash to the database
            string hashedPassword = cryptoService.Compute(model.Password);

            SignupUser signup = new SignupUser
            {
                Email        = model.Email,
                Password     = hashedPassword,
                PasswordSalt = salt,
                Timezone     = model.Timezone,
                UserName     = model.UserName
            };

            try
            {
                using (ApplicationDbContext context = new ApplicationDbContext())
                {
                    context.SignupUser.Add(signup);
                    context.SaveChanges();
                    return(Content(HttpStatusCode.OK, new { success = true }));
                }
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, new { error = ex }));
            }


            //return Request.CreateResponse(HttpStatusCode.OK, new { success=true });
        }
예제 #5
0
 private void HandleSignupCompleted(object sender, SignupResultModel e)
 {
 }