Exemplo n.º 1
0
        //======================================Register====================================
        public int CreateUser(RegisterAddRequest registerAddRequest)
        {
            int    id           = 0;
            string password     = registerAddRequest.Password;
            string salt         = _cryptographyService.GenerateRandomString(RAND_LENGTH);
            string passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT);

            this._dataProvider.ExecuteNonQuery(
                // "Emma_User_Insert",
                "HRB_user_insert",
                inputParamMapper : delegate(SqlParameterCollection paramList)
            {
                SqlParameter param  = new SqlParameter();
                param.ParameterName = "@Id";
                param.SqlDbType     = System.Data.SqlDbType.Int;
                param.Direction     = System.Data.ParameterDirection.Output;
                paramList.Add(param);

                paramList.AddWithValue("Email", registerAddRequest.Email);
                paramList.AddWithValue("FirstName", registerAddRequest.FirstName);
                paramList.AddWithValue("MiddleInitial", registerAddRequest.MiddleInitial);
                paramList.AddWithValue("LastName", registerAddRequest.LastName);
                paramList.AddWithValue("Password", passwordHash);
                paramList.AddWithValue("ConfirmPassword", passwordHash);
                paramList.AddWithValue("Salt", salt);
            },
                returnParameters : delegate(SqlParameterCollection paramList)
            {
                id = (int)paramList["@Id"].Value;
            }
                );
            return(id);
        }
Exemplo n.º 2
0
        public int Register(RegisterAddRequest model)
        {
            int    userId         = 0;
            string password       = model.Password;
            string salt           = BCrypt.Net.BCrypt.GenerateSalt();
            string hashedPassword = BCrypt.Net.BCrypt.HashPassword(password, salt);

            this._dataProvider.ExecuteNonQuery(
                "Registration_Insert",
                inputParamMapper : delegate(SqlParameterCollection paramCol)
            {
                SqlParameter parm = new SqlParameter
                {
                    ParameterName = "@Id",
                    SqlDbType     = System.Data.SqlDbType.Int,
                    Direction     = System.Data.ParameterDirection.Output
                };
                paramCol.Add(parm);
                paramCol.AddWithValue("@FirstName", model.FirstName);
                paramCol.AddWithValue("@MiddleInitial", model.MiddleInitial);
                paramCol.AddWithValue("@LastName", model.LastName);
                paramCol.AddWithValue("@Email", model.Email);
                paramCol.AddWithValue("@Salt", salt);
                paramCol.AddWithValue("@Password", hashedPassword);
                paramCol.AddWithValue("@ModifiedBy", model.ModifiedBy);
            },
                returnParameters : delegate(SqlParameterCollection paramCol)
            {
                userId = (int)paramCol["@Id"].Value;
            }
                );
            return(userId);
        }
Exemplo n.º 3
0
 public HttpResponseMessage RegisterUser(RegisterAddRequest model)
 {
     try
     {
         ItemResponse <int> resp = new ItemResponse <int>();
         resp.Item = _userService.Register(model);
         return(Request.CreateResponse(HttpStatusCode.OK, resp));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Exemplo n.º 4
0
        //=============controllerfor register==================
        public HttpResponseMessage CreateUser(RegisterAddRequest model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int id = _svc.CreateUser(model);
                    ItemResponse <int> resp = new ItemResponse <int>();
                    resp.Item = id;

                    return(Request.CreateResponse(HttpStatusCode.OK, resp));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }