예제 #1
0
        public async Task <IHttpActionResult> Post(RegistrationDTO item)
        {
            var userId = string.Empty;

            if (!ModelState.IsValid)
            {
                LogManager.WriteLog("error", userId, this.Request.RequestUri.PathAndQuery, string.Format("{0}:{1}", JsonConvert.SerializeObject(item), JsonConvert.SerializeObject(ModelState))).Forget();
                return(BadRequest(ModelState));
            }
            var error = string.Empty;

            if (string.IsNullOrEmpty(item.Mobile) && string.IsNullOrEmpty(item.Email))
            {
                error = "Mobile or email are required";
                DataClassesManager.ControllerLog("error", userId, this.Request.RequestUri.PathAndQuery, error);
                return(BadRequest(error));
            }

            long?preUserId = 0;
            var  password  = AuthorizationUtils.HashPassword(item.Password);

            var validation = DataClassesManager.Register(item.Username.ToLower(), password.Hash, password.Salt, item.CountryId, IdentityUtils.GetIdentitiesXML(item.Mobile, item.Email), out preUserId, out error);

            if (!string.IsNullOrEmpty(error))
            {
                LogManager.WriteLog("error", userId, this.Request.RequestUri.PathAndQuery, error).Forget();
                return(BadRequest(error));
            }

            foreach (var v in validation)
            {
                IdentityUtils.ValidateIdentity(v);
            }

            LogManager.WriteLog("info", userId, this.Request.RequestUri.PathAndQuery, string.Format("{0}:{1}:{2}", preUserId, JsonConvert.SerializeObject(item), JsonConvert.SerializeObject(validation))).Forget();

            return(Ok(new
            {
                RefId = preUserId,
                Identity = from x in validation
                           where x.Immediate
                           select new IdentityDTO
                {
                    TypeId = x.TypeId,
                    Value = x.Identity,
                    Token = x.Token
                }
            }
                      ));
        }