コード例 #1
0
        public async Task <AuthenticationResponse> Register(RegisterationRequest request)
        {
            if ((await repository.Filter(u => u.Email == request.Email)).Count() > 0)
            {
                return new AuthenticationResponse {
                           Status = AuthenticationResponse.StatusEnum.Fail, Token = null, UserData = null
                }
            }
            ;
            User user = new User {
                Email    = request.Email,
                Name     = request.Name,
                Password = BCrypt.Net.BCrypt.HashPassword(request.Password)
            };

            if (request.Image != null)
            {
                string fileName = Guid.NewGuid().ToString() + Path.GetExtension(request.Image.FileName);

                using (FileStream fs = new FileStream(Path.Combine(env.WebRootPath + "/ProfileImages", fileName), FileMode.Create))
                {
                    await request.Image.CopyToAsync(fs);
                }
                user.Image = "ProfileImages/" + fileName;
            }
            return(new AuthenticationResponse
            {
                UserData = mapper.Map <UserDTO>(await repository.Create(user)),
                Token = token.Generate(user),
                Status = AuthenticationResponse.StatusEnum.OK
            });
        }
コード例 #2
0
ファイル: AuthController.cs プロジェクト: sumitc91/M2E
        public JsonResult CreateAccount(RegisterationRequest req)
        {
            var returnUrl = "/";
            var referral  = Request.QueryString["ref"];

            if (req.Source != "web")
            {
                return(Json("Not Web"));
            }
            var webRegisterService = new WebRegister();

            return(Json(webRegisterService.WebRegisterService(req, Request)));
        }
コード例 #3
0
        public async Task <IActionResult> Register([FromForm] RegisterationRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var response = await service.Register(request);

            if (response.Status == Http.Responses.AuthenticationResponse.StatusEnum.Fail)
            {
                return(BadRequest(new { Email = new string[] { "This email is used" } }));
            }
            return(StatusCode(201, response));
        }
コード例 #4
0
ファイル: WebRegister.cs プロジェクト: sumitc91/M2E
        public ResponseModel <String> WebRegisterService(RegisterationRequest req, HttpRequestBase request)
        {
            var response = new ResponseModel <String>();

            if (_db.Users.Any(x => x.Username == req.Username))
            {
                response.Status  = 409;
                response.Message = "conflict";
                return(response);
            }

            var guid = Guid.NewGuid().ToString();
            var user = new User
            {
                Username  = req.Username,
                Password  = EncryptionClass.Md5Hash(req.Password),
                Source    = req.Source,
                isActive  = "false",
                Type      = req.Type,
                guid      = Guid.NewGuid().ToString(),
                FirstName = req.FirstName,
                LastName  = req.LastName,
                gender    = "NA",
                ImageUrl  = "NA"
            };

            _db.Users.Add(user);

            if (!string.IsNullOrEmpty(req.Referral))
            {
                var dbRecommedBy = new RecommendedBy
                {
                    RecommendedFrom = req.Referral,
                    RecommendedTo   = req.Username
                };
                _db.RecommendedBies.Add(dbRecommedBy);
            }
            if (req.Type == "client")
            {
                var dbClientDetails = new ClientDetail
                {
                    Username    = req.Username,
                    CompanyName = req.CompanyName
                };
                _db.ClientDetails.Add(dbClientDetails);
            }
            var dbValidateUserKey = new ValidateUserKey
            {
                Username = req.Username,
                guid     = guid
            };

            _db.ValidateUserKeys.Add(dbValidateUserKey);

            try
            {
                _db.SaveChanges();
                SendAccountCreationValidationEmail.SendAccountCreationValidationEmailMessage(req.Username, guid, request);
            }
            catch (DbEntityValidationException e)
            {
                DbContextException.LogDbContextException(e);
                response.Status  = 500;
                response.Message = "Internal Server Error !!!";
                return(response);
            }

            response.Status  = 200;
            response.Message = "success";
            response.Payload = "Account Created";

            return(response);
        }