Exemplo n.º 1
0
        public UserCreateResult RegisterUser(ApiUserEntity user)
        {
            if (user == null)
            {
                return(UserCreateResult.Failed);
            }

            // check if the username doesnt exist already
            if (_userRepository.UserNameExists(user.Username))
            {
                return(UserCreateResult.NameAlreadyExists);
            }

            // create password for this user.
            user.Salt     = PasswordHash.CreateSalt(user.Username, NumberExtension.GetRandomUniqueCodeWithLength(10));
            user.Password = PasswordHash.HashPassword(user.Salt, user.Password);

            // add the user.
            _userRepository.Add(user);

            // save changes.
            _uow.SaveChanges();

            return(UserCreateResult.Success);
        }
Exemplo n.º 2
0
        public async Task <object> Read([FromRoute] long id)
        {
            try
            {
                var jObject = new JObject
                {
                    { "id", id }
                };
                var requestModel = ValidateRequest <ReadRequestModel>(jObject);
                if (!requestModel.IsValid)
                {
                    return(RespondError(HttpStatusCode.BadRequest, requestModel.ResponseErrors));
                }
                using (AsyncScopedLifestyle.BeginScope(_container))
                {
                    var apiUserUseCase = _container.GetInstance <IApiUserUseCase>();
                    var apiUserEntity  = new ApiUserEntity()
                    {
                        Id = requestModel.id
                    };
                    var readResultFlow = await apiUserUseCase.Read(apiUserEntity);

                    if (readResultFlow.IsSuccess())
                    {
                        return(RespondSuccess(HttpStatusCode.OK, new { apiUser = readResultFlow.Result }));
                    }
                    return(RespondError(HttpStatusCode.NotFound, readResultFlow.Message));
                }
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 3
0
        public HttpResponseMessage Post(ApiUserEntity apiUserEntity)
        {
            if (!ModelState.IsValid)
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ODataError { ErrorCode = "2", Message = "Modelstate is invalid" });

            var result = this._apiUserService.RegisterUser(apiUserEntity);

            if (result == UserCreateResult.Success)
                return Request.CreateResponse(HttpStatusCode.OK, apiUserEntity);

            // http://www.odata.org/documentation/odata-version-3-0/json-verbose-format/#representingerrorsinaresponse
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ODataError { ErrorCode = result.ToString(), Message = "todo: generate error messages!" });
        }
Exemplo n.º 4
0
        public async Task <ResultFlow <ApiUserEntity> > Read(ApiUserEntity model)
        {
            try {
                var readResultFlow = await _apiUserLogic.Read(model);

                if (readResultFlow.IsException())
                {
                    return(ResultFlowFactory.Exception <ApiUserEntity>(readResultFlow.Message));
                }
                return(ResultFlowFactory.Success <ApiUserEntity>(readResultFlow.Result));
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 5
0
        public async Task <ResultFlow <ApiUserEntity> > Read(ApiUserEntity model)
        {
            try {
                var readResultFlow = await _apiUserRepository.Read(model);

                if (readResultFlow.IsSuccess() && readResultFlow.Result == null)
                {
                    return(ResultFlowFactory.Exception <ApiUserEntity>("Api user not found"));
                }
                return(ResultFlowFactory.Success <ApiUserEntity>(readResultFlow.Result));
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 判断手机号是否已经使用
        /// </summary>
        /// <param name="telephone"></param>
        /// <returns></returns>
        public JsonResult CheckTelephone(string telephone)
        {
            ApiUserEntity  viewE     = new ApiUserEntity();
            CustomerEntity chkENtity = CustomerService.GetCustomerByTelephone(telephone);

            if (chkENtity == null)
            {
                viewE.code           = "200";
                viewE.codeinfo       = "未使用!";
                viewE.customerEntity = chkENtity;
            }
            else
            {
                viewE.code     = "201";
                viewE.codeinfo = "已使用!";
            }
            return(Json(JsonHelper.ToJson(viewE)));
        }
Exemplo n.º 7
0
        public async Task <ResultFlow <ApiUserEntity> > Read(ApiUserEntity model)
        {
            try {
                var sql    = @"SELECT * 
                            FROM api_user
                            WHERE id = @Id";
                var result = await _connection.QueryAsync <ApiUserEntity>(
                    sql,
                    param : new
                {
                    Id = model.Id
                }
                    );

                return(ResultFlowFactory.Success <ApiUserEntity>(result.FirstOrDefault()));
            } catch {
                throw;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 忘记密码  直接更新数据库中密码
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="telephone"></param>
        /// <param name="vcode"></param>
        /// <param name="newpassword"></param>
        /// <returns></returns>
        public JsonResult Forget(string telephone, string vcode, string newpassword)
        {
            ApiUserEntity  viewE     = new ApiUserEntity();
            CustomerEntity chkENtity = CustomerService.UpdatePassword(telephone, EncryptHelper.MD5Encrypt(newpassword), vcode);

            if (chkENtity != null)
            {
                viewE.customerEntity = chkENtity;
                viewE.code           = "200";
                viewE.codeinfo       = "密码修改成功!";
            }
            else
            {
                viewE.code     = "201";
                viewE.codeinfo = "密码修改失败!";
            }

            return(Json(JsonHelper.ToJson(viewE)));
        }
Exemplo n.º 9
0
        /// <summary>
        /// 手机注册返回验证码
        /// </summary>
        /// <param name="telephone"></param>
        /// <param name="timeout">默认10分钟</param>
        /// <returns></returns>
        public JsonResult RegisterVCode(string telephone, string timeout = "10")
        {
            ApiUserEntity viewE = new ApiUserEntity();
            string        vcode = SendSMSService.SendVCodeMess(telephone, timeout.ToInt(0));

            if (!string.IsNullOrEmpty(vcode))
            {
                viewE.vcode    = vcode;
                viewE.code     = "200";
                viewE.codeinfo = "验证码返回成功!";
            }
            else
            {
                viewE.vcode    = "";
                viewE.code     = "201";
                viewE.codeinfo = "验证码返回失败!";
            }

            return(Json(JsonHelper.ToJson(viewE)));
        }
Exemplo n.º 10
0
        public UserCreateResult RegisterUser(ApiUserEntity user)
        {
            if (user == null)
                return UserCreateResult.Failed;

            // check if the username doesnt exist already
            if (_userRepository.UserNameExists(user.Username))
                return UserCreateResult.NameAlreadyExists;

            // create password for this user.
            user.Salt = PasswordHash.CreateSalt(user.Username, NumberExtension.GetRandomUniqueCodeWithLength(10));
            user.Password = PasswordHash.HashPassword(user.Salt, user.Password);

            // add the user.
            _userRepository.Add(user);

            // save changes.
            _uow.SaveChanges();

            return UserCreateResult.Success;
        }
Exemplo n.º 11
0
        public HttpResponseMessage Post(ApiUserEntity apiUserEntity)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ODataError {
                    ErrorCode = "2", Message = "Modelstate is invalid"
                }));
            }

            var result = this._apiUserService.RegisterUser(apiUserEntity);

            if (result == UserCreateResult.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, apiUserEntity));
            }

            // http://www.odata.org/documentation/odata-version-3-0/json-verbose-format/#representingerrorsinaresponse
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ODataError {
                ErrorCode = result.ToString(), Message = "todo: generate error messages!"
            }));
        }
Exemplo n.º 12
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="telephone"></param>
        /// <param name="vcode"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public JsonResult Register(string telephone, string vcode, string password)
        {
            ApiUserEntity  viewE     = new ApiUserEntity();
            CustomerEntity chkENtity = CustomerService.GetCustomerByTelephone(telephone);

            if (chkENtity == null)
            {
                //判断验证码是否正确、是否已经过期了
                VerificationCodeEntity VCode = BaseDataService.CheckVerificationCode(telephone, vcode);
                if (VCode != null)
                {
                    CustomerEntity entity = CustomerService.Register(telephone, EncryptHelper.MD5Encrypt(password), vcode);
                    if (entity != null)
                    {
                        viewE.code           = "200";
                        viewE.codeinfo       = "注册成功!";
                        viewE.customerEntity = entity;
                    }
                    else
                    {
                        viewE.code     = "201";
                        viewE.codeinfo = "注册失败!";
                    }
                }
                else
                {
                    viewE.code     = "202";
                    viewE.codeinfo = "验证码已经过期!";
                }
            }
            else
            {
                viewE.code     = "203";
                viewE.codeinfo = "手机号已经注册!";
            }

            return(Json(JsonHelper.ToJson(viewE)));
        }
Exemplo n.º 13
0
        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="telephone"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public JsonResult Login(string telephone, string password)
        {
            ApiUserEntity viewE = new ApiUserEntity();

            CustomerEntity entity = CustomerService.Login(telephone, EncryptHelper.MD5Encrypt(password));

            if (entity != null)
            {
                viewE.code           = "200";
                viewE.codeinfo       = "登录成功!";
                viewE.customerEntity = entity;
                viewE.token          = Guid.NewGuid().ToString();
            }
            else
            {
                viewE.code           = "201";
                viewE.codeinfo       = "登录失败!";
                viewE.customerEntity = entity;
                viewE.token          = Guid.NewGuid().ToString();
            }


            return(Json(JsonHelper.ToJson(viewE)));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="telephone"></param>
        /// <param name="vcode"></param>
        /// <param name="password"></param>
        /// <param name="salerSource">销售源头:门店:Store 业务员:Saler</param>
        /// <returns></returns>
        public JsonResult RegisterNew(string telephone, string vcode, string SourceType, string salesCode)
        {
            telephone  = Request["telephone"];
            vcode      = Request["vcode"];
            SourceType = Request["SourceType"];
            salesCode  = Request["Scode"];
            string         password  = "******";
            ApiUserEntity  viewE     = new ApiUserEntity();
            CustomerEntity chkENtity = CustomerService.GetCustomerByTelephone(telephone);

            if (chkENtity == null)
            {
                //判断验证码是否正确、是否已经过期了
                VerificationCodeEntity VCode = BaseDataService.CheckVerificationCode(telephone, vcode);
                if (string.IsNullOrEmpty(VCode.Mobile))
                {
                    CustomerEntity entity = CustomerService.Register(telephone, EncryptHelper.MD5Encrypt(password), vcode, 4);
                    if (entity != null)
                    {
                        #region 注册成功与业务员建立关系


                        List <SalerRelationEntity> listSaler = SalerService.GetSalerCustomerByTelephone(telephone);
                        if (listSaler != null && listSaler.Count > 0)
                        {
                        }
                        else
                        {
                            //绑定和业务员之间的关系
                            SalerRelationEntity sr = new SalerRelationEntity();
                            sr.SalerCode = salesCode;
                            //sr.SalerID = sid;
                            sr.CustomerID   = entity.CustomerID;
                            sr.CustomerCode = entity.CustomerCode;
                            sr.SalerSource  = SourceType;
                            SalerService.CreateRelation(sr);

                            #endregion

                            viewE.code           = "200";
                            viewE.codeinfo       = "注册成功!";
                            viewE.customerEntity = entity;
                        }

                        #region 给客户发送短信
                        SendSMSService.SendRegisterMess(telephone, password);
                        #endregion
                    }
                    else
                    {
                        viewE.code     = "201";
                        viewE.codeinfo = "注册失败!";
                    }
                }
                else
                {
                    viewE.code     = "202";
                    viewE.codeinfo = "验证码已经过期!";
                }
            }
            else
            {
                viewE.code     = "203";
                viewE.codeinfo = "手机号已经注册!";
            }
            return(Json("ok"));
        }